/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vs.kindlecoll.UI;

import com.vs.kindlecoll.Beans.BooksCollection;
import java.util.Locale;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author volodymyr.sadovyy
 */
public class CollectionTreeModel extends DefaultTreeModel {

    public CollectionTreeModel(TreeNode root) {
        super(root);
    }

    @Override
    public void valueForPathChanged(TreePath path, Object newValue) {
        DefaultMutableTreeNode aNode = (DefaultMutableTreeNode) path.getLastPathComponent();

        if (aNode.getUserObject() instanceof BooksCollection) {
            BooksCollection bc = (BooksCollection) aNode.getUserObject();
            bc.setName(newValue.toString() + "@" + Locale.getDefault());
            aNode.setUserObject(bc);
            nodeChanged(aNode);
        }
    }
}
